Matrix Plots


In [2]:
import seaborn as sns
%matplotlib inline
tips = sns.load_dataset('tips')
flights = sns.load_dataset('flights')
tips.head()


Out[2]:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4

In [3]:
flights.head()


Out[3]:
year month passengers
0 1949 January 112
1 1949 February 118
2 1949 March 132
3 1949 April 129
4 1949 May 121

In [5]:
tc = tips.corr()

In [8]:
sns.heatmap(tc, annot=True, cmap='coolwarm')


Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0xaf95cc0>

In [9]:
flights


Out[9]:
year month passengers
0 1949 January 112
1 1949 February 118
2 1949 March 132
3 1949 April 129
4 1949 May 121
5 1949 June 135
6 1949 July 148
7 1949 August 148
8 1949 September 136
9 1949 October 119
10 1949 November 104
11 1949 December 118
12 1950 January 115
13 1950 February 126
14 1950 March 141
15 1950 April 135
16 1950 May 125
17 1950 June 149
18 1950 July 170
19 1950 August 170
20 1950 September 158
21 1950 October 133
22 1950 November 114
23 1950 December 140
24 1951 January 145
25 1951 February 150
26 1951 March 178
27 1951 April 163
28 1951 May 172
29 1951 June 178
... ... ... ...
114 1958 July 491
115 1958 August 505
116 1958 September 404
117 1958 October 359
118 1958 November 310
119 1958 December 337
120 1959 January 360
121 1959 February 342
122 1959 March 406
123 1959 April 396
124 1959 May 420
125 1959 June 472
126 1959 July 548
127 1959 August 559
128 1959 September 463
129 1959 October 407
130 1959 November 362
131 1959 December 405
132 1960 January 417
133 1960 February 391
134 1960 March 419
135 1960 April 461
136 1960 May 472
137 1960 June 535
138 1960 July 622
139 1960 August 606
140 1960 September 508
141 1960 October 461
142 1960 November 390
143 1960 December 432

144 rows × 3 columns


In [13]:
fp = flights.pivot_table(index='month', columns='year', values='passengers')

In [18]:
# sns.heatmap(fp, cmap='coolwarm', linecolor='white', linewidths=1)
sns.heatmap(fp)


Out[18]:
<matplotlib.axes._subplots.AxesSubplot at 0xd29b940>

In [21]:
sns.clustermap(fp, cmap='coolwarm', standard_scale=1)


Out[21]:
<seaborn.matrix.ClusterGrid at 0xd89b7f0>

Regression Plots


In [22]:
import seaborn as sns
%matplotlib inline
tips = sns.load_dataset('tips')
tips.head()


Out[22]:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4

In [26]:
sns.lmplot(x='total_bill', y='tip', data=tips, hue='sex', markers=['o', 'v'], scatter_kws={'s':100})


Out[26]:
<seaborn.axisgrid.FacetGrid at 0xe525080>

In [32]:
sns.lmplot(x='total_bill', y='tip', data=tips, col='day', hue='sex', aspect=0.6, size=8)


Out[32]:
<seaborn.axisgrid.FacetGrid at 0x10015438>

Grids


In [37]:
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
iris = sns.load_dataset('iris')
iris.head()


Out[37]:
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa

In [40]:
g = sns.PairGrid(iris)
g.map_diag(sns.distplot)
g.map_upper(plt.scatter)
g.map_lower(sns.kdeplot)


D:\Usuarios\westerley.reis\AppData\Local\Continuum\Anaconda3\lib\site-packages\statsmodels\nonparametric\kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j
Out[40]:
<seaborn.axisgrid.PairGrid at 0x179b5ba8>

In [41]:
tips = sns.load_dataset('tips')
tips.head()


Out[41]:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4

In [44]:
g = sns.FacetGrid(data=tips, col='time', row='smoker')
g.map(plt.scatter, 'total_bill', 'tip')


Out[44]:
<seaborn.axisgrid.FacetGrid at 0x18e45da0>

Style and Color


In [45]:
import seaborn as sns
%matplotlib inline
tips = sns.load_dataset('tips')
tips.head()


Out[45]:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4

In [62]:
#sns.set_style('ticks')
#plt.figure(figsize=(12,3))
sns.set_context('paper')
sns.countplot(x='sex', data=tips)


Out[62]:
<matplotlib.axes._subplots.AxesSubplot at 0x16646e10>

In [64]:
sns.lmplot(x='total_bill', y='tip', data=tips, hue='sex', palette='seismic')


Out[64]:
<seaborn.axisgrid.FacetGrid at 0x16691b00>